Practical Bayesian Inference by CORYN A. L. BAILER-JONES
Author:CORYN A. L. BAILER-JONES
Language: eng
Format: epub
Publisher: Cambridge University Press
library(MASS) # for truehist and geyser data
attach(geyser)
pdf("kde.pdf", 8,4)
par(mfrow=c(1,2), mar=c(3.5,3.0,0.5,0.5), oma=c(0.5,0.5,0.5,0.5),
mgp=c(2.2,0.8,0), cex=1.0)
truehist(duration, h=0.25, xlim=c(0.5, 6), ymax=1.1, ylab="density",
col="white", lwd=0.5)
lines(density(duration, kernel="rectangular", bw=0.1, n=2^10), lwd=1.5)
lines(density(duration, kernel="rectangular", bw=0.2, n=2^10), lwd=2,
col="grey60")
truehist(duration, h=0.25, xlim=c(0.5, 6), ymax=1.1, ylab="density",
col="white", lwd=0.5)
lines(density(duration, kernel="gaussian", bw=0.1, n=2^10), lwd=1.5)
lines(density(duration, kernel="gaussian", bw=0.2, n=2^10), lwd=2,
col="grey60")
dev.off()
detach(geyser)
You may be interested in looking at what the function density actually produces. If you do
attach(geyser)
mydense <- density(duration, kernel="gaussian", bw=0.2, n=2^10)
then attributes(mydense) lists all the things computed and stored by density. This produces the following.
$names
[1] "x" "y" "bw" "n" "call" "data.name" "has.na"
$class
[1] "density"
The attribute x is the vector of n points at which the density was estimated, to give the values y. You can retrieve these values with mydense$x. Note that density estimation does not produce an analytic function, but rather evaluations of the estimator at a pre-defined set of points. The function lines in the above code just connects the x and y values in order to plot an apparently continuous function.
The idea of kernel density estimation extends to higher dimensions. The following code is an example in two dimensions applied to the geyser data. It produces figure 7.4.
R file: kde2d.R
##### Investigate kernel density estimation in 2D
##### Modified from the example given by Venables & Ripley (2002)
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Modelling of Convective Heat and Mass Transfer in Rotating Flows by Igor V. Shevchuk(6411)
Weapons of Math Destruction by Cathy O'Neil(6222)
Factfulness: Ten Reasons We're Wrong About the World – and Why Things Are Better Than You Think by Hans Rosling(4718)
A Mind For Numbers: How to Excel at Math and Science (Even If You Flunked Algebra) by Barbara Oakley(3265)
Descartes' Error by Antonio Damasio(3252)
Factfulness_Ten Reasons We're Wrong About the World_and Why Things Are Better Than You Think by Hans Rosling(3218)
TCP IP by Todd Lammle(3161)
Fooled by Randomness: The Hidden Role of Chance in Life and in the Markets by Nassim Nicholas Taleb(3083)
Applied Predictive Modeling by Max Kuhn & Kjell Johnson(3045)
The Tyranny of Metrics by Jerry Z. Muller(3034)
The Book of Numbers by Peter Bentley(2936)
The Great Unknown by Marcus du Sautoy(2666)
Once Upon an Algorithm by Martin Erwig(2628)
Easy Algebra Step-by-Step by Sandra Luna McCune(2607)
Lady Luck by Kristen Ashley(2557)
Practical Guide To Principal Component Methods in R (Multivariate Analysis Book 2) by Alboukadel Kassambara(2520)
Police Exams Prep 2018-2019 by Kaplan Test Prep(2518)
All Things Reconsidered by Bill Thompson III(2374)
Linear Time-Invariant Systems, Behaviors and Modules by Ulrich Oberst & Martin Scheicher & Ingrid Scheicher(2349)